package com.edar.dao.factory;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.edar.dao.GenericDao;
import com.edar.dao.impl.GenericHibernateDao;

public class DaoFactory {
	@Autowired
	private static SessionFactory sessionFactory;
	@SuppressWarnings("rawtypes")
	private static Map<String,GenericDao>  DAO_MAP = new HashMap<String,GenericDao>();
	@SuppressWarnings("unchecked")
	public static <T,ID extends Serializable> GenericDao<T, ID> getGenericDao(Class<T> clazz){
		if(!DAO_MAP.containsKey(clazz.getName())){
			GenericDao<T, Serializable> genericDao = new GenericHibernateDao<T, Serializable>();
			genericDao.setSessionFactory(sessionFactory);
			DAO_MAP.put(clazz.getName(), genericDao);
		}
		return DAO_MAP.get(clazz.getName());
	}
}
